#ifndef __HASHFUNCTION_HPP__
#define __HASHFUNCTION_HPP__

/* Do not modify this file! */

#include <string>

#include "HashValue.hpp"
#include "md5.h"

/**
 * Generic hash function interface
 */
class HashFunction {

	private:
		HashValue value;
		md5_state_s state;
		md5_state_s savedState;

	public:
		HashFunction(unsigned int hashLength);

		void clear();

		/**
		 * Append string for hashing.
		 * Calling hash("a"), hash("b") is equivalent to calling hash("ab").
		 * Calling hash("a"), saveState(), hash("x"), loadState(), hash("b") is equivalent to calling hash("ab").
		 */
		void hash(const std::string &text);

		void saveState();

		void loadState();

		/**
		 * Calculate hash.
		 */
		void finish();

		/**
		 * Return calculated hash - don't forget to call finish() first
		 */
		const HashValue& getHash() const;

		/**
		 * Convenience function that calls hash(text), finish(), and getHash()
		 */
		static HashValue calculateHash(unsigned int length, const std::string &text);

};
#endif

